package 
{
	
	import flash.display.Sprite;
	import flash.display3D.Context3D;
	import flash.events.Event;
	import starling.core.Starling;
	
	// for drugondrop
	import flash.filesystem.File;
	import flash.filesystem.FileStream;
	import flash.filesystem.FileMode;
	import flash.utils.ByteArray;
	import flash.events.NativeDragEvent;
	import flash.desktop.NativeDragManager;
	import flash.events.Event
	import flash.desktop.Clipboard;
	import flash.desktop.ClipboardFormats;
	import flash.desktop.NativeDragManager;
	
	[SWF(width="500", height="420", frameRate="30", backgroundColor="#FFFFFF")]
	/**
	 * ...
	 * @author artem.kolesnikov 
	 */
	
	public class Main extends Sprite 
	{
		
		public static var context:Context3D;
		private var _starling:Starling;
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			
			_starling = new Starling(Game, stage);
			_starling.start();
			
			context = _starling.context;
			
			var bg:Sprite = new Sprite();
			bg.graphics.beginFill(0xFFFFFF);
			bg.alpha = 0;
			bg.graphics.drawRect(0, 0, 500, 420);
			bg.graphics.endFill();
			addChild(bg);
			
			this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragIn);
			this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDrop);
			this.addEventListener(NativeDragEvent.NATIVE_DRAG_EXIT, onDragExit);
		}
		
		private function onDragIn(event:NativeDragEvent):void {
			NativeDragManager.acceptDragDrop(this);
		}
		
		private function onDrop(event:NativeDragEvent):void {
			doSome(event);
		}
		
		private function onDragExit(event:NativeDragEvent):void {
			//trace("onDragExit");
		}
		
		private function doSome(event:NativeDragEvent):void {
			var dropFiles:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
			for each (var file:File in dropFiles){
				//switch (file.extension){
				trace(">>>", file.name, file.nativePath);
				//duplicate(file);
			}
		}
	}
	
}